package net.jeanhwea.gold.model;

import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;

import net.jeanhwea.gold.bean.Item;

import com.mysql.jdbc.Connection;

public class DataManager {
  private String databaseURL = "";
  private String databaseUser = "";
  private String databasePasswd = "";
  
  public void setDbURL(String aURL) {
    this.databaseURL = aURL;
  }
  
  public String getDbURL() {
    return this.databaseURL;
  }

  public void setDbUser(String aUser) {
    this.databaseUser = aUser;
  }
  
  public String getDbUser() {
    return this.databaseUser;
  }
  
  public void setDbPasswd(String aPasswd) {
    this.databasePasswd = aPasswd;
  }
  
  public String getDbPasswd() {
    return this.databasePasswd;
  }
  
  public Connection getConnection(){
    Connection conn = null;
    try{
      conn = (Connection) DriverManager.getConnection(getDbURL(), getDbUser(), getDbPasswd());
    }catch(SQLException e){
      System.out.println("Could not connect to DB: " + e.getMessage());
    }
    return conn;
  }
  
  public void closeConnection(Connection aConn) {
    if(aConn != null){
      try{
        aConn.close();
      }catch(SQLException e){ }
    }
  }
  
  /**
   * some search action
   */
  
  public ArrayList<Item> getResultByID(int id) {
    return ItemPeer.searchItemById(this, id);
  }
  
  
  
  
  
}
